home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / nt / jx4nt125.zip / UNIBLOCK.C < prev    next >
C/C++ Source or Header  |  1994-05-20  |  3KB  |  100 lines

  1. /* uniblock.c ... convert Forth 1024-byte BLOCK files to Forth 1024-widechar BLOCK files.
  2.  * Copyright (C) 1993 by
  3.  * jack j. woehr, p.o. box 51, golden, colorado 80402-0051
  4.  * jax@well.sf.ca.us JAX on GEnie 72203.1320@compuserve.com
  5.  * SYSOP, RealTime Control & Forth Board [RCFB] (303) 278-0364
  6.  * All Rights Reserved
  7.  */
  8.  
  9. /*
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * (at your option) any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details. (doc\license.txt)
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  */
  24.  
  25. #include <windows.h>
  26. #include <stdio.h>
  27. #include <string.h>
  28.  
  29. #define USAGE    "Usage: %s sourcefile destfile\n (or %s /? for help)\n", argv[0], argv[0]
  30.  
  31. SECURITY_ATTRIBUTES myAttrib;
  32. DWORD numRead;
  33. DWORD numWritten;
  34. char    buff[1024];
  35. char    fubb[2048];
  36.  
  37. int main (int argc, char *argv[]) {
  38.  
  39.     DWORD    i;
  40.     int    j = 0;
  41.  
  42.     DWORD temp = 0;
  43.  
  44.     HANDLE ifh;
  45.     HANDLE ofh;
  46.  
  47.     if (argc > 3) {
  48.         fprintf (stderr, USAGE);
  49.         return 99;
  50.     }
  51.  
  52.     if    (argc == 2)
  53.         if (!(strcmp (argv[1], "/?"))) {
  54.             fprintf (stderr, USAGE);
  55.             fprintf (stderr, "%s\n%s\n%s\n",
  56.                 "Converts the ASCII file specified by the sourcefile argument",
  57.                 "to a Unicode file twice the size.",
  58.                 "Creates destination file or silently overwrites existing file of same name.");
  59.             return    99;
  60.             }
  61.  
  62.     if (argc < 3) {
  63.         fprintf (stderr, USAGE);
  64.         return 99;
  65.     }
  66.  
  67.     myAttrib.nLength = sizeof (myAttrib);
  68.     myAttrib.lpSecurityDescriptor = NULL;
  69.     myAttrib.bInheritHandle = TRUE;
  70.  
  71.     if    (INVALID_HANDLE_VALUE == 
  72.             (ifh = CreateFile (argv[1], GENERIC_READ, 0, &myAttrib, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,0)))
  73.         {
  74.         temp = GetLastError();
  75.         fprintf (stderr, "Couldn't open source file.\n");
  76.         return temp;
  77.         }
  78.  
  79.     if    (INVALID_HANDLE_VALUE == 
  80.             (ofh = CreateFile (argv[2], GENERIC_WRITE, 0, &myAttrib, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL,0)))
  81.         {
  82.         temp = GetLastError();
  83.         fprintf (stderr, "Couldn't open destination file.\n");
  84.         return temp;
  85.         }
  86.  
  87.     while (ReadFile (ifh, &buff, 1024, &numRead, 0)) {
  88.         if (numRead == 0)
  89.             return 0;
  90.         for (i = 0; i < numRead; i++) {
  91.             fubb[i*2] = buff[i];
  92.             fubb[(i*2)+1] = 0;
  93.             }
  94.         WriteFile (ofh, &fubb, numRead*2, &numWritten, 0);
  95.         }
  96.  
  97.     return 0;
  98. }
  99.  
  100.